#include <iostream>
#include <vector>
#include "geometry.h"

int main()
{
   int n;
   std::cin >> n;
   std::vector<point> points;
   for (int i = 0; i < n; i++)
   {
      double x, y;
      std::cin >> x >> y;
      points.push_back(point(x, y));
   }

   kd2tree diagram = kd2tree(points);

   int m;
   std::cin >> m;
   std::cout.precision(20);
   for (int i = 0; i < m; i++)
   {
      double x, y;
      std::cin >> x >> y;
      point ans = diagram.find_nearest(point(x, y));
      std::cout << ans.x << " " << ans.y << "\n";
   }
  
   return 0;
}